package course.web;
import course.domain.Course;
import course.domain.Personal;

import java.security.Principal;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;

import course.domain.User;
import course.repository.UserRepository;
import course.repository.*;
import lombok.extern.slf4j.Slf4j;


@Slf4j
@Controller
@RequestMapping("/result")
public class ResultController {
	private PersonalRepository PersonalInfoRepo;
	private UserRepository userRepo;
	@Autowired
	public ResultController(PersonalRepository PersonalInfoRepo
			,UserRepository userRepo) {
		this.PersonalInfoRepo=PersonalInfoRepo;
		this.userRepo=userRepo;
	}
	@GetMapping
	public String showResult(Model model,Principal principal) {
		/*System.out.println(person);
		System.out.println(course);*/
	List <Personal> personals = new ArrayList<>();
	PersonalInfoRepo.findAll().forEach(i -> personals.add(i));
	model.addAttribute("personals",personals);
	log.info("person: "+personals);
	String username=principal.getName();
    User user=userRepo.findByUsername(username);
    model.addAttribute("user",user);
	return "result"; 
	}
}
